package cn.kinoko.common.base.model;

import lombok.Data;
import lombok.ToString;

/**
 * @author kinoko
 */
@Data
@ToString
public class BaseQuery {

    /**
     * 默认当前页码
     */
    static final int DEFAULT_PAGE = 1;
    /**
     * 默认页码大小
     */
    static final int DEFAULT_SIZE = 10;

    /**
     * 不分页。最大条数
     */
    static final int MAX_SIZE = 999999999;


    private Integer page;

    private Integer size;
    private Long id;

    public void setPage(Integer page) {
        this.page = page;
        if (page == null || page == 0) {
            this.page = DEFAULT_PAGE;
        }
    }

    public Integer getPage() {
        return id != null ? DEFAULT_PAGE : page;
    }

    public void setSize(Integer size) {
        this.size = size;
        if (size == null) {
            this.size = DEFAULT_SIZE;
        }
    }

    /**
     * 设置每页条数为最大条数9999999999
     */
    public BaseQuery setMaxSize() {
        this.page = DEFAULT_PAGE;
        this.size = MAX_SIZE;
        return this;
    }

}
